import {
    getAuthList
} from './models/getAuthList.model';
import {
    createView
} from './views/create.view';
import {
    validate
} from './validate';
import {
    submit
} from './submit';
import{
    modal
}from '../common/layer';

const createBtnHandler = () => {



    getAuthList(-1, function (data) {


            modal('新增', createView(data));

            $(".modal-form input").iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            });

            $('#submitBtn').click(() => {
                    let data = {};
                    $.each($('#form').serializeArray(), (key, val) => {
                        data[val.name] = val.value;
                    });

                    let authlist = $("#authlist .checked input").map(function () {
                        return $(this).val();
                    }).get().join(",");
                     data.authlist = authlist;

                if (!validate(data)) {
                    return;
                }
                submit(GLOBAL_roleAddUrl, data);
            });

    });

};

export {
    createBtnHandler
}